package com.hmall.common.config;

import com.hmall.common.interceptors.UserInfoInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration//配置类需要被spring扫描到
@ConditionalOnClass(DispatcherServlet.class)
//springmvc的核心，网关无springmvc，所以无DispatcherServlet，其他微服务有所以可以识别。配置生效的条件注解
public class MvcConfig implements WebMvcConfigurer {
    //拦截器注册器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserInfoInterceptor());
        //不设置路径就是全局都做

    }
}
